package
{
	import flash.display.MovieClip;

	public class LaunchPadObject
	{
		public var name:String;
		public var pos:Vector2;
		public var nx:Number;
		public var ny:Number;
		public var r:Number;
		public var strength:Number;
		public var mc:MovieClip;

		public function LaunchPadObject()
		{
			this.name = "launch pad";
			this.pos = new Vector2(54, 23);
			this.nx = 0;
			this.ny = 1;
			this.r = Main.getInstance().tiles.xw * 0.5;
			this.strength = Main.getInstance().tiles.xw * 0.428571428571429;
			Main.getInstance().objects.Register(this);
			this.mc = Main.getInstance().gfx.CreateSprite("debugLaunchPadMC", NinjaGraphicsSystem.LAYER_WALLS);
			this.mc.visible = false;
		}

		public function Destruct():void
		{
			Main.getInstance().gfx.DestroyMC(this.mc);
			this.mc = null;
		}

		public function Init(params):void
		{
			var _local2 = params;
			if (_local2.length == 4)
			{
				this.pos.x = _local2[0];
				this.pos.y = _local2[1];
				this.nx = _local2[2];
				this.ny = _local2[3];
				this.mc.scaleX = (this.mc.scaleY = 2.5 * this.r);
				this.mc.x = this.pos.x;
				this.mc.y = this.pos.y;
				this.mc.visible = true;
				this.mc.gotoAndStop("launch_idle");
				if (this.nx < 0)
				{
					if (this.ny < 0)
					{
						this.mc.rotation = -45;
					}
					else if (0 < this.ny)
					{
						this.mc.rotation = -135;
					}
					else
					{
						this.mc.rotation = -90;
					}
				}
				else if (0 < this.nx)
				{
					if (this.ny < 0)
					{
						this.mc.rotation = 45;
					}
					else if (0 < this.ny)
					{
						this.mc.rotation = 135;
					}
					else
					{
						this.mc.rotation = 90;
					}
				}
				else if (this.ny < 0)
				{
					this.mc.rotation = 0;
				}
				else if (0 < this.ny)
				{
					this.mc.rotation = 180;
				}
				Main.getInstance().objects.AddToGrid(this);
				Main.getInstance().objects.Moved(this);
			}
		}

		public function UnInit():void
		{
			Main.getInstance().objects.RemoveFromGrid(this);
		}

		public function DumpInitData():String
		{
			return "" + this.pos.x + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.pos.y + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.nx + NinjaGame.OBJPARAM_SEPERATION_CHAR + this.ny;
		}

		public function IdleAfterDeath():void
		{
			Main.getInstance().objects.RemoveFromGrid(this);
		}

		public function TestVsPlayer(guy):void
		{
			var _local3 = guy;
			var p = _local3.pos;
			var dx = (this.pos.x - _local3.pos.x);
			var dy = (this.pos.y - _local3.pos.y);
			var _local2 = _local3.r;
			if (Math.sqrt((dx * dx) + (dy * dy)) < (this.r + _local2))
			{
				var tx = (this.pos.x - (p.x - (this.nx * _local2)));
				var ty = (this.pos.y - (p.y - (this.ny * _local2)));
				var dp = ((tx * this.nx) + (ty * this.ny));
				if (0 <= dp)
				{
					var mult = 1;
					if (this.ny < 0)
					{
						mult = mult + Math.abs(this.ny);
					}
					this.mc.gotoAndPlay("launch_triggered");
					_local3.Launch(this.nx * this.strength, (this.ny * this.strength) * mult);
				}
			}
		}
	}
}